package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.aop.annotation.LogAnnotation;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.TBacklistEntity;
import com.company.project.service.TBacklistService;



/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-10-29 22:09:34
 */
@Api(value = "黑名单")
@Controller
@RequestMapping("/")
public class TBacklistController {
    @Autowired
    private TBacklistService tBacklistService;

    /**
    * 跳转到页面
    */
    @GetMapping("/index/tBacklist")
    public String tBacklist() {
        return "tbacklist/list";
        }

    @ApiOperation(value = "新增")
    @LogAnnotation(title = "黑名单", action = "新增")
    @PostMapping("tBacklist/add")
    //@RequiresPermissions("tBacklist:add")
    @ResponseBody
    public DataResult add(@RequestBody TBacklistEntity tBacklist){
        return tBacklistService.addBacklist(tBacklist);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("tBacklist/delete")
    @RequiresPermissions("tBacklist:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tBacklistService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("tBacklist/update")
    @RequiresPermissions("tBacklist:update")
    @ResponseBody
    public DataResult update(@RequestBody TBacklistEntity tBacklist){
        tBacklistService.updateById(tBacklist);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("tBacklist/listByPage")
    @RequiresPermissions("tBacklist:list")
    @LogAnnotation(title = "黑名单", action = "查询分页数据")
    @ResponseBody
    public DataResult findListByPage(@RequestBody TBacklistEntity tBacklist){
        Page page = new Page(tBacklist.getPage(), tBacklist.getLimit());
        LambdaQueryWrapper<TBacklistEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(TBacklistEntity::getId, tBacklist.getId());
        if(tBacklist.getPhone() != null) queryWrapper.like(TBacklistEntity::getPhone,tBacklist.getPhone());
        queryWrapper.orderByDesc(TBacklistEntity::getAddtime);
        IPage<TBacklistEntity> iPage = tBacklistService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
